package com.GlobalPaint.app.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.GlobalPaint.app.Base.JobWantedBean;
import com.GlobalPaint.app.R;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.List;

/**
 * Created by Administrator on 2018/1/7 0007.
 */

public class JobWantedAdapter extends XRecyclerView.Adapter<JobWantedAdapter.ViewHoler>{
    private List<JobWantedBean.DataBean> list;
    public JobWantedAdapter(List<JobWantedBean.DataBean> list, Context context) {
        this.list=list;
    }

    @Override
    public JobWantedAdapter.ViewHoler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.frament_recruit_item, parent, false);
        JobWantedAdapter.ViewHoler holder = new JobWantedAdapter.ViewHoler(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(JobWantedAdapter.ViewHoler holder, int position) {
        String companyname = list.get(position).getContent() ==
                null ? "" : list.get(position).getContent();
        String title = list.get(position).getTitle() ==
                null ? "" : list.get(position).getTitle();
        String money = String.valueOf(list.get(position).getMoney()) ==
                null ? "" : String.valueOf(list.get(position).getMoney());
        String publishtime = list.get(position).getPublishtime() ==
                null ? "" : list.get(position).getPublishtime();
        holder.tv_companyname.setText(companyname);
        holder.tv_title.setText(title);
        holder.tv_money.setText(money);
        if(publishtime.length()>10){
            holder.tv_publishtime.setText(publishtime.substring(0,10));
        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHoler extends RecyclerView.ViewHolder {

        private final ImageView imge;
        private final TextView tv_title;
        private final TextView tv_companyname;
        private final TextView tv_city;
        private final TextView tv_money;
        private final TextView tv_publishtime;
        public ViewHoler(View itemView) {
            super(itemView);
            imge = (ImageView)itemView. findViewById(R.id.imge);
            tv_title = (TextView)itemView.findViewById(R.id.tv_title);
            tv_companyname = (TextView)itemView.findViewById(R.id.tv_companyname);
            tv_city = (TextView)itemView.findViewById(R.id.tv_city);
            tv_money = (TextView)itemView.findViewById(R.id.tv_money);
            tv_publishtime = (TextView)itemView.findViewById(R.id.tv_publishtime);
        }
    }
}
